% this code is for Jumps and Post-FOMC Announcement Returns in Currency Markets
% Considering the report, this code is to investigate the realized
% volatility patterns around FOMC announcements

% consider total, jdnv, jupv, jrv // and jdnv is positive or not 


%% 1. realized volatility pattern (figure 3)

clear
clc

load(using 15min filtered return and estimated 12 hr measures)

nfomc=nansum(fomcwindow(:,1),1)/(npday*4);

tplre=nan(npday*4,nfomc,nc+1);
tplreie=nan(npday*4,nfomc,nc+1);
tpjdn=nan(npday*4,nfomc,nc+1);
tpjup=nan(npday*4,nfomc,nc+1);
tpnojp=nan(npday*4,nfomc,nc+1);

for k=1:4*npday
    tp=find(fomcwindow(:,2)==k);
    for j=1:nfomc
        for i=1:nc+1
            tplreie(k,j,i)=lreie(tp(j,1),i);
            tplre(k,j,i)=lre(tp(j,1),i);
            if tplreie(k,j,i)==1
                tpjdn(k,j,i)=0;
                tpjup(k,j,i)=0;
                tpnojp(k,j,i)=0;
                if jdn(tp(j,1),i)>0
                    tpjdn(k,j,i)=lre(tp(j,1),i);
                end
                if jup(tp(j,1),i)>0
                    tpjup(k,j,i)=lre(tp(j,1),i);
                end
                if jp(tp(j,1),i)==0
                    tpnojp(k,j,i)=lre(tp(j,1),i);
                end
            end
        end
    end
end
clear k j i

% to report
repvolp=nan(npday*4,nc+1);
repjdnvp=nan(npday*4,nc+1);
repjupvp=nan(npday*4,nc+1);
repjrvp=nan(npday*4,nc+1);

for i=1:nc+1
    repvolp(:,i)=100*sqrt(npday*252)*nanmean(abs(tplre(:,:,i)),2);
    repjdnvp(:,i)=100*sqrt(npday*252)*nanmean(abs(tpjdn(:,:,i)),2);
    repjupvp(:,i)=100*sqrt(npday*252)*nanmean(abs(tpjup(:,:,i)),2);
    repjrvp(:,i)=100*sqrt(npday*252)*nanmean(abs(tpnojp(:,:,i)),2);
end
clear i

repcompvolpattern=nan(npday*4,4*(nc+1));

for i=1:nc+1
    repcompvolpattern(:,(i-1)*4+1)=repvolp(:,i);
    repcompvolpattern(:,(i-1)*4+3)=repjdnvp(:,i);
    repcompvolpattern(:,(i-1)*4+4)=repjupvp(:,i);
    repcompvolpattern(:,(i-1)*4+2)=repjrvp(:,i);
end
clear i


repavgvolpattern=nan(npday*4,4);    % it is figure 3 data set

repavgvolpattern(:,1)=nanmean(repvolp(:,1:nc),2);
repavgvolpattern(:,4)=nanmean(repjupvp(:,1:nc),2);
repavgvolpattern(:,3)=nanmean(repjdnvp(:,1:nc),2);
repavgvolpattern(:,2)=nanmean(repjrvp(:,1:nc),2);

